<?php

namespace app\common\service;

use app\admin\model\Api;
use app\http\exception\ApiException;
use randy\tools\units\ExtendQueryHelper;

class ApiService extends BaseService
{
        public function getApiList(ExtendQueryHelper $extendQueryHelper,$data)
        {
           $query = Api::build()
                                    ->where($extendQueryHelper->where)
                                    ->order($extendQueryHelper->sort, $extendQueryHelper->order);
           $list = $extendQueryHelper->is_page ? $query->_paginate() : $query->select();
           return $list;
       }

       public  function getApiItem( $id ){
           return Api::build()->findOrFail($id);
       }

       public  function delApiItem( $id ){
            $info = Api::find($id);
            return $info->delete();
       }

       public  function setApiItem($id, $data){
            $info = Api::find($id);
            $info->save($data);
           return $info;
       }


       public  function addApiItem($data)
       {
           $model = new Api();
            $model->save($data);
            return $model;
       }


}
